package com.xzy.demo.controller;

import com.xzy.demo.entry.Staff;
import com.xzy.demo.server.StaffService;
import com.xzy.mybatis.pojo.User;
import com.xzy.mybatis.service.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


@RestController
@RequestMapping("/test")
public class testControlle {

    @Autowired private StaffService staffService;
    @Autowired private UserMapper userMapper;


    @GetMapping(value = "getName")
    public Page<Staff> hello(){
        Page<Staff> userList = staffService.findStaffList(1, 2);
        return userList;
    }

    @RequestMapping(value = "test")
    public String test(Model model){
        model.addAttribute("msg","thymeleaf");
        model.addAttribute("msg","<h3>标题H3</h3>");
        model.addAttribute("list", Arrays.asList("1111","2222","3333"));

        return "test";
    }
    @RequestMapping("/add/{name}/{password}")
    public String addUser(@PathVariable("name") String name,@PathVariable("password") String password){
        User user = new User(null,name,password);
        userMapper.addUser(user);
        return "OK!";
    }

    @RequestMapping("/del/{id}")
    public String delUser(@PathVariable("id") Integer id){
        userMapper.delUser(id);
        return "OK!";
    }


    @RequestMapping("/listUser")
    public List<User> listUser(){
        List<User> userList = userMapper.getUserList();
        return userList;
    }

    @RequestMapping("/getUser/{id}")
    public User getUser(@PathVariable("id") Integer id){
        User user = userMapper.getUserById(id);
        return user;
    }





}
